//
//  XDLMUIFactory.m
//  xindailianmeng
//
//  Created by 许佳奇 on 17/1/17.
//  Copyright © 2017年 xindailianmeng.cn. All rights reserved.
//

#import "XDLMUIFactory.h"

@implementation XDLMUIFactory
+ (UIBarButtonItem *)createBBIWithImageStr:(NSString *)imageStr target:(id)target action:(SEL)action {
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
    btn.frame = CGRectMake(0, 0, 10, 17);
    
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    [btn setBackgroundImage:[UIImage imageNamed:imageStr] forState:UIControlStateNormal];
    
    UIBarButtonItem *bbi = [[UIBarButtonItem alloc] initWithCustomView:btn];
    return bbi;
}

+ (UIBarButtonItem *)createBBIWithTitleStr:(NSString *)titleStr target:(id)target action:(SEL)action {
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
    btn.frame = CGRectMake(0, 0, 60,60);
    btn.titleLabel.adjustsFontSizeToFitWidth = YES;
    
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn setTitle:titleStr forState:UIControlStateNormal];
    
    UIBarButtonItem *bbi = [[UIBarButtonItem alloc] initWithCustomView:btn];
    return bbi;
    
}

+ (UILabel *)createLabelWithFrame:(CGRect)frame text:(NSString *)text textFont:(UIFont *)font textColor:(UIColor *)color {
    
    UILabel * label = [[UILabel alloc] initWithFrame:frame];
    label.text = text;
    label.textColor = color;
    label.font = font;
    label.adjustsFontSizeToFitWidth = YES;
    label.textAlignment = NSTextAlignmentCenter;
    
    return label;
    
}

+ (UIButton *)createButtonWithFrame:(CGRect)fram text:(NSString *)text textFont:(UIFont *)font textColor:(UIColor *)textColor backgroundColor:(UIColor *)backgroundColor{
    
    
    float height = fram.size.height /2;
    UIButton * button = [[UIButton alloc] initWithFrame:fram];
    button.backgroundColor = backgroundColor;
    [button setTitle:text forState:UIControlStateNormal];
    
    [button setTitleColor:textColor forState:UIControlStateNormal];
    button.titleLabel.font = font;
    button.layer.cornerRadius = height;
    
    
    
    return button;
    
}

@end
